package cc.sheji.config;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;


@Configuration
public class StaticConfig {

    /**
     * 商户号
     */
    @Value("${merchantId}")

    public String merchantId ;
    /**
     * 商户API私钥路径
     */

    @Value( "${privateKeyPath}")
    public String privateKeyPath;
    /**
     * 商户证书序列号
     */
    @Value( "${merchantSerialNumber}")
    public String merchantSerialNumber ;

    /**
     * 商户APIV3密钥
     */

    @Value("${apiV3key}")
    public String apiV3key ;

    RSAAutoCertificateConfig build;

    public synchronized Config  getConfig(){

        if(build==null)
          build = new RSAAutoCertificateConfig.Builder()
                .merchantId(merchantId)
                .privateKeyFromPath(privateKeyPath)
                .merchantSerialNumber(merchantSerialNumber)
                .apiV3Key(apiV3key)
                .build();

        return   build;

    }

}
